Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fast rendering #1835

Merged
merged 16 commits into from
Aug 23, 2023
Merged

Conversation

paulpdaniels
Copy link
Collaborator

@paulpdaniels paulpdaniels commented Aug 13, 2023

Introduces a Renderer type and a DocumentRenderer implementation which generalizes the the rendering of a Document so that it can work with both query and schema documents (the inverted parser).

Running the benchmarks:

// Without document caching
[info] Benchmark                             Mode  Cnt       Score      Error  Units
[info] GraphQLBenchmarks.renderCaliban      thrpt    5  103325.148 ± 5125.692  ops/s
[info] GraphQLBenchmarks.renderCalibanFast  thrpt    5  235363.260 ± 1367.168  ops/s

// With document caching
[info] Benchmark                             Mode  Cnt       Score      Error  Units
[info] GraphQLBenchmarks.renderCaliban      thrpt    5  106606.129 ±  511.746  ops/s
[info] GraphQLBenchmarks.renderCalibanFast  thrpt    5  842012.538 ± 1521.568  ops/s

The above benchmarks show a 2x improvement over the base rendering (calling GraphQL#render) when using .toDocument, however, if we cache the document (something I added on this PR) we see an 8x improvement on rendering.

This should help with use cases that require the document to be re-serialized (e.g. federation, stitching, etc.)

TODO:

  • Finish Compact parsing
  • Migrate remaining "rendering" components
  • Add more tests

@ghostdogpr
Copy link
Owner

ghostdogpr commented Aug 14, 2023

Can this replace the implementation of .render entirely?

Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Had a look through the code, couldn't find anything really standing out. Just some minor recommendations for performance

core/src/main/scala/caliban/rendering/Renderer.scala Outdated Show resolved Hide resolved
core/src/main/scala/caliban/rendering/Renderer.scala Outdated Show resolved Hide resolved
core/src/main/scala/caliban/rendering/Renderer.scala Outdated Show resolved Hide resolved
core/src/main/scala/caliban/rendering/Renderer.scala Outdated Show resolved Hide resolved
core/src/main/scala/caliban/rendering/Renderer.scala Outdated Show resolved Hide resolved
core/src/main/scala/caliban/rendering/Renderer.scala Outdated Show resolved Hide resolved
@frekw
Copy link
Collaborator

frekw commented Aug 14, 2023

Super clean! I wonder if this also solves #1794?

@paulpdaniels paulpdaniels marked this pull request as ready for review August 18, 2023 17:36
Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@paulpdaniels paulpdaniels merged commit 7896591 into ghostdogpr:series/2.x Aug 23, 2023
@paulpdaniels paulpdaniels deleted the add-fast-rendering branch August 23, 2023 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants